const app=getApp()
Page({
  data: {
    now:{},
    airColor:'yellow',
    airLevel:'良',
    future:[],
    isShow:false,
    advShow:true
  },
  toCityList(){
    wx.navigateTo({
      url: '/pages/city/city',
    })
  },
  onShow() {
    // console.log(app.city)
    wx.request({
      url:app.city?'https://v0.yiketianqi.com/free/day?appid=85828447&appsecret=4aQfuXXK&city='+app.city:'https://v0.yiketianqi.com/free/day?appid=85828447&appsecret=4aQfuXXK',
      success:(res)=>{
        // console.log(res)
        let airText=''
        let air=res.data.air
        let airColor=''
        if(air<50){
          airText='优'
          airColor='green'
        }else if(air>=50 && air<100){
          airText='良'
          airColor='yellow'
        }else if(air>=100 && air<150){
          airText='轻度污染'
          airColor='orange'
        }else if(air>=150 && air<200){
          airText='中度污染'
          airColor='red'
        }else if(air>=200){
          airText='重度污染'
          airColor='purple'
        }
        this.setData({
          now:res.data,
          airLevel:airText,
          isShow:true,
          airColor
        })
      }
    })
    wx.request({
      url: app.city?'https://v0.yiketianqi.com/free/week?appid=85828447&appsecret=4aQfuXXK&city='+app.city:'https://v0.yiketianqi.com/free/week?appid=85828447&appsecret=4aQfuXXK',
      success:(res)=>{
        // console.log(res)
        this.setData({
          future:res.data.data
        })
      }
    })
    // console.log(this.data.future)
  },
  closeAdv(){
    this.setData({
      advShow:false
    })
  }
})